package com.ai.zuochengyun.phase01.class03;

public class Code07_DoubleLinkedList {
    public static class DoubleNode {
        int value;
        DoubleNode next;
        DoubleNode last;

        public DoubleNode(int value) {
            this.value = value;
        }
        public DoubleNode next(DoubleNode next) {
            this.next = next;
            return this;
        }
    }

    public static DoubleNode reverseDoubleLinkedList(DoubleNode head) {
        if (head == null) {
            return null;
        }

        DoubleNode pre = null;
        DoubleNode next = null;
        while (head != null) {
            next = head.next;
            head.next = pre;
            head.last = next;
            pre = head;
            head = next;
        }
        return pre;
    }
}
